﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;

namespace Xm.CustomDesigner.UI.Adorners
{
    internal class CustomNodeAdorner : Adorner
    {
        //private readonly UIElement _objElement;

        public CustomNodeAdorner(UIElement adornedElement) : base(adornedElement)
        {
            //_objElement = adornedElement;
        }

        //重写OnRender方法
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            //绘制装饰元素的矩形边框
            Rect adornedElementRect = new Rect(this.AdornedElement.DesiredSize);

            // Some arbitrary drawing implements.
            SolidColorBrush renderBrush = new SolidColorBrush(Colors.Green);
            renderBrush.Opacity = 0.2;
            Pen renderPen = new Pen(new SolidColorBrush(Colors.Navy), 1.5);
            double renderRadius = 5.0;

            //获取左右两侧中间点
            var leftPoint = new Point(adornedElementRect.Left, adornedElementRect.Top + adornedElementRect.Height / 2);
            var rightPoint = new Point(adornedElementRect.Right, adornedElementRect.Top + adornedElementRect.Height / 2);

            // Draw a circle at each corner.
            drawingContext.DrawEllipse(renderBrush, renderPen, leftPoint, renderRadius, renderRadius);
            drawingContext.DrawEllipse(renderBrush, renderPen, rightPoint, renderRadius, renderRadius);
        }
    }
}
